package com.itboye.sunsun.shop.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.itboye.sunsun.R;
import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.GouWuZiXunBean;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.support.BaseActivity;
import com.itboye.sunsun.utils.SPUtils;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XRequestListener;

public class WoYaoZiXunActivity extends BaseActivity implements OnClickListener {

	EditText edt_content;
	Button ok;
	private String goodsId;// 提交结果
	boolean result;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);

		setContentView(R.layout.activity_woyao_zixun);

		findViewById(R.id.back).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		initData();

	}

	private void initData() {
		// TODO Auto-generated method stub
		Intent intent = getIntent();
		goodsId = intent.getStringExtra("goodsId");
	}

	@Override
	public void onClick(View v) {
		// TODO| Auto-generated method stub
		switch (v.getId()) {
		case R.id.ok:
			String content = edt_content.getText().toString().trim();
			if (content.isEmpty()) {
				Toast.makeText(this, "还没有输入咨询内容", 0).show();
			} else {
				isSuccess(content);
			}
			break;

		default:
			break;
		}

	}

	public void isSuccess(String str) {

		String uid = (String) SPUtils
				.get(App.ctx, null, SPContants.USER_ID, "");
		String userName = (String) SPUtils.get(App.ctx, null,
				SPContants.USERNAME, "");
		// SPContants.USERNAME
		MyJsonRequest<String> request = new MyJsonRequest.Builder<String>()
				.apiVer("100").param("pid", goodsId).param("ask_content", str)
				.param("ask_uid", uid).param("ask_username", userName)
				.typeKey("BY_Product_ask")
				.requestListener(new XRequestListener<String>() {

					@Override
					public void onResponse(String arg0) {
						Toast.makeText(WoYaoZiXunActivity.this, arg0, 0).show();
						finish();
					}
				}).errorListener(new XErrorListener() {

					@Override
					public void onErrorResponse(Exception exception, int code,
							String msg) {
						Toast.makeText(WoYaoZiXunActivity.this, "提交失败", 0).show();
					}
				}).build();
		HttpRequest.getDefaultRequestQueue().add(request);
	}

}
